<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>下载歌曲</title>
</head>
<body>
    <div style="margin: auto;">
        <input type="text" name="song_name" id="songdownload">
        <button id="btn">下载该歌曲</button>
    </div>

    <script>
        var btn=document.getElementById("btn");
        console.log(btn);
        var songvalue=document.getElementById("songdownload");
        console.log(songvalue);

        btn.addEventListener("click",function(){
            res_url="/getsong?song_name="+songvalue.value;
            var xhr = new XMLHttpRequest();
            xhr.open('GET', res_url, true); // 设置请求方法、URL和异步标志
            xhr.onreadystatechange = function() {
                if (xhr.readyState === XMLHttpRequest.DONE) {
                    if (xhr.status === 200) {
                        // var response = JSON.parse(xhr.responseText);
                        console.log("200")
                        // 处理响应数据
                    } else {
                        console.log("失败")
                        // 处理请求错误
                    }
                }
            };
            xhr.send(); // 发送请求
        })
        
    </script>
</body>
</html>